<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\LeavingMessage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class LeavingMessageController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new LeavingMessage(['user','prize.prize']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.name','用户');
            $grid->column('prize.prize.name','奖品');
            $grid->column('name');
            $grid->column('tel');
            $grid->column('address');
//            $grid->column('status');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            // 禁用过滤器按钮
            $grid->disableFilterButton();
            $grid->setActionClass(Grid\Displayers\Actions::class);
            $grid->disableEditButton();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            //禁用创建按钮
            $grid->disableCreateButton();
            $grid->export();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new LeavingMessage(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('prize_user_id');
            $show->field('name');
            $show->field('tel');
            $show->field('address');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new LeavingMessage(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('prize_user_id');
            $form->text('name');
            $form->text('tel');
            $form->text('address');
            $form->text('status');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
